package com.wjh.controller;

import com.wjh.bean.Constants;
import com.wjh.bean.Result;
import com.wjh.feign.PayServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/6/27.
 * @Modified By:
 */
@Controller
public class PayController {

    @Autowired
    private PayServiceFeign payServiceFegin;

    /**
     * 订单支付
     * @param payToken
     * @param resp
     * @throws IOException
     */
    @GetMapping("/pay/{payToken}")
    public void pay(@PathVariable("payToken") String payToken, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (StringUtils.isEmpty(payToken)) {
            writer.print("订单号不能为空");
            return;
        }
        Result result = payServiceFegin.findPayToken(payToken);
        if (result.getCode()!= Constants.HTTP_RES_CODE_200) {
            writer.print(result.getMsg());
            return;
        }
        LinkedHashMap mapPayInfo = (LinkedHashMap)result.getData();
        String payHtml=(String) mapPayInfo.get("payHtml");
        writer.print(payHtml);
        writer.close();
    }


}
